package com.sanjiahantang.youjiarole.module.me.order.views.impl;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.sanjiahantang.youjiarole.R;
import com.sanjiahantang.youjiarole.base.BaseMvpActivity;
import com.sanjiahantang.youjiarole.base.BaseView;
import com.sanjiahantang.youjiarole.config.ConfigValue;
import com.sanjiahantang.youjiarole.module.me.order.presenters.OrderPresenter;
import com.sanjiahantang.youjiarole.module.me.order.views.OrderView;


/**
 * Created by zy on 2017/9/26.
 * 我的订单
 */
public class MyOrderActivity extends BaseMvpActivity<OrderView,OrderPresenter> implements View.OnClickListener,OrderView{
    private RecyclerView recyclerView;
    private LinearLayoutManager layoutManager;
    private RadioButton rbAll,rbUnPay,rbPartPay,rbPayed,rbComplete;

    private boolean cartFlag = false,laod = false;//放回购物车标识
    int page = 1;
    @Override
    public void initView() {
        setContentView(R.layout.activity_me_order);
        findViewById(R.id.fl_Left).setOnClickListener(this);
        TextView title = (TextView) findViewById(R.id.title);
        title.setText("商品订单");
        recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
        layoutManager = new LinearLayoutManager($this);
        recyclerView.setLayoutManager(layoutManager);

        rbAll = (RadioButton) findViewById(R.id.rbAll);
        rbUnPay = (RadioButton) findViewById(R.id.rbUnPay);
        rbPartPay = (RadioButton) findViewById(R.id.rbPartPay);
        rbPayed = (RadioButton) findViewById(R.id.rbPayed);
        rbComplete = (RadioButton) findViewById(R.id.rbComplete);


        rbAll.setOnClickListener(this);
        rbUnPay.setOnClickListener(this);
        rbPartPay.setOnClickListener(this);
        rbPayed.setOnClickListener(this);
        rbComplete.setOnClickListener(this);

        findViewById(R.id.flAll).setOnClickListener(this);
        findViewById(R.id.flUnPay).setOnClickListener(this);
        findViewById(R.id.flPartPay).setOnClickListener(this);
        findViewById(R.id.flPayed).setOnClickListener(this);
        findViewById(R.id.flComplete).setOnClickListener(this);
        presenter.setOnLoadListener(new BaseView.OnLoadListener() {
            @Override
            public void onLoad(Object content) {
                Object[] param = (Object[]) content;
                switch ((int)param[0]){
                    case CALLBACK_TYPE_RECYCLER_ADAPTER:
                        recyclerView.setAdapter((RecyclerView.Adapter) param[1]);
                        break;
                }
            }
        });

        int type1 = getIntent().getIntExtra("type1",1);
        int type2 = getIntent().getIntExtra("type2",OrderView.TYPE_ALL);

        initType2(type2);
    }

    private void initType2(int type2) {
        ConfigValue.TYPE_SELECT = type2;
        rbAll.setChecked(false);
        rbUnPay.setChecked(false);
        rbPartPay.setChecked(false);
        rbPayed.setChecked(false);
        rbComplete.setChecked(false);

        switch (type2){
            case TYPE_ALL:
                rbAll.setChecked(true);
                break;

            case TYPE_UN_PAY:
                rbUnPay.setChecked(true);
                break;

            case TYPE_PART_PAY:
                rbPartPay.setChecked(true);
                break;

            case TYPE_PAYED:
                rbPayed.setChecked(true);
                break;

            case TYPE_COMPLETE:
                rbComplete.setChecked(true);
                break;
        }
    }


    @Override
    public void initData() {

    }



    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.fl_Left:
                finish();
                break;
            case R.id.rbAll:case R.id.flAll://全部
                ConfigValue.TYPE_SELECT = OrderView.TYPE_ALL;
                checkStatusRadio(rbAll, ConfigValue.TYPE_SELECT);
                break;
            case R.id.rbUnPay:case R.id.flUnPay://未付款
                ConfigValue.TYPE_SELECT = OrderView.TYPE_UN_PAY;
                checkStatusRadio(rbUnPay,ConfigValue.TYPE_SELECT);
                break;
            case R.id.rbPartPay:case R.id.flPartPay://部分付款
                ConfigValue.TYPE_SELECT = OrderView.TYPE_PART_PAY;
                checkStatusRadio(rbPartPay,ConfigValue.TYPE_SELECT);
                break;
            case R.id.rbPayed:case R.id.flPayed://已付款
                ConfigValue.TYPE_SELECT = OrderView.TYPE_PAYED;
                checkStatusRadio(rbPayed,ConfigValue.TYPE_SELECT);
                break;
            case R.id.rbComplete:case R.id.flComplete://已完成
                ConfigValue.TYPE_SELECT = OrderView.TYPE_COMPLETE;
                checkStatusRadio(rbComplete,ConfigValue.TYPE_SELECT);
                break;
        }
    }
    private void checkStatusRadio(RadioButton rb,int tag ){
        rbAll.setChecked(false);
        rbUnPay.setChecked(false);
        rbPartPay.setChecked(false);
        rbPayed.setChecked(false);
        rbComplete.setChecked(false);
        rb.setChecked(true);
        presenter.loadOrderList($this,1,tag);
    }

    @Override
    protected void onResume() {
        super.onResume();
        page = 1;
        presenter.loadOrderList($this, 1,ConfigValue.TYPE_SELECT);
    }

    @Override
    public OrderPresenter initPresenter() {
        return new OrderPresenter();
    }


    @Override
    public void showProgress() {
        super.showProgress($this);
    }

    @Override
    public void hideProgress() {
        super.hideProgress();
    }
}
